package tfts

import "fmt"

func (f *Fight) Sniper(active, skillRange, duration int) *Fight {
	atkRange := 4
	amp := 0
	switch active {
	case 2:
		f.Add(AMP(10))
		amp = 4
	case 3:
		f.Add(AMP(15))
		amp = 6
	case 4:
		f.Add(AMP(25))
		amp = 9
	case 5:
		f.Add(AMP(30))
		amp = 12
	default:
		panic("wrong classes num")
	}

	f.Add(AMP(atkRange * amp))

	a := NewAction(f).Repeat(1).On(BeforeCastE)
	a.buff = NewBuff(TimeGoE, duration, AMP(skillRange*amp))
	a.TraceAction("Sniper")

	return f
}

func (f *Fight) Duelist(active int) *Fight {
	speed := 0
	switch active {
	case 2:
		speed = 4
	case 4:
		speed = 7
	case 6:
		speed = 10
		f.Add(DR(12))
	}
	a := NewAction(f, AS(speed)).Stack(1, 12).On(AttackE)
	a.name = "Duelist"
	return f
}

func (f *Fight) Edgeload(active int) *Fight {
	f.Add(AS(20))
	switch active {
	case 2:
		f.Add(OMP(10))
		f.Add(AD(15))
	case 4:
		f.Add(OMP(12))
		f.Add(AD(35))
	case 6:
		f.Add(OMP(15))
		f.Add(AD(60))
	}
	return f
}

func (f *Fight) Executioner(active int) *Fight {
	f.Add(Critable())
	switch active {
	case 2:
		f.Add(CritRate(25))
		f.Add(CritAmp(10))
	case 3:
		f.Add(CritRate(35))
		f.Add(CritAmp(12))
	case 4:
		f.Add(CritRate(45))
		f.Add(CritAmp(15))
	case 5:
		f.Add(CritRate(55))
		f.Add(CritAmp(20))
	default:
		panic("wrong classes num")
	}
	return f
}

func (f *Fight) Prodigy(active int) *Fight {
	mps := 0
	switch active {
	case 2:
		mps = 3
	case 3:
		mps = 5
	case 4:
		mps = 7
	case 5:
		mps = 9
		f.EndTime += 2
	}
	f.MPS("Prodigy", mps)
	return f
}

func (f *Fight) Prodigy0(active int) *Fight {
	mps := 0
	switch active {
	case 2:
		mps = 1
	case 3:
		mps = 2
	case 4:
		mps = 3
	case 5:
		mps = 4
	}
	f.MPS("Prodigy*", mps)
	return f
}

func (f *Fight) Sorcerer(active int) *Fight {
	switch active {
	case 2:
		f.Add(AP(20))
		f.Add(UnqAmp(4))
	case 4:
		f.Add(AP(50))
		f.Add(UnqAmp(5))
	case 6:
		f.Add(AP(80))
		f.Add(UnqAmp(12))
	}
	return f
}

func (f *Fight) Strategist(active int) *Fight {
	switch active {
	case 2:
		f.Add(AMP(5 * 3))
	case 3:
		f.Add(AMP(8 * 3))
	case 4:
		f.Add(AMP(12 * 3))
	case 5:
		f.Add(AMP(15 * 3))
	}
	return f
}

func (f *Fight) Strategist0(active int) *Fight {
	switch active {
	case 2:
		f.Add(AMP(5))
	case 3:
		f.Add(AMP(8))
	case 4:
		f.Add(AMP(12))
	case 15:
		f.Add(AMP(15))
	}
	return f
}

func (f *Fight) Protector(active int) *Fight {
	percent := 0
	switch active {
	//case 2:
	//	percent = 32
	//case 4:
	//	percent = 64
	//case 6:
	//	percent = 96
	case 2:
		percent = 20
	case 4:
		percent = 40
	case 6:
		percent = 60
	default:
		panic("Invalid active number")
	}
	shield := fmt.Sprintf("%d*hp", percent)
	a := NewAction(f).Once(8).On(TimeGoE)
	a.name = "Protector"
	a.Shield = shield
	f.Add(DR(2))
	return f
}

func (f *Fight) Heavyweight(active int) *Fight {
	f.Add(HP(100))
	percent := 0.0
	switch active {
	case 2:
		f.Add(HpAmp(20))
		percent = 0.002
	case 4:
		f.Add(HpAmp(40))
		percent = 0.004
	case 6:
		f.Add(HpAmp(55))
		percent = 0.006
	}
	f.PrevCall(func(fight *Fight) {
		health := fight.hp()
		ad := int(health * percent)
		f.Add(AD(ad))
		TraceLog("%4.1f秒:[Heavyweight]增加%d攻击力\n", f.Current(), ad)
	})
	return f
}

func (f *Fight) Judgement(active int) *Fight {
	switch active {
	case 2:
		f.PrevCall(AddBuff("JugDR", 10, TimeGoE, DR(25)))
		NewAction(f, DR(15)).Once(11).On(TimeGoE)
	case 4:
		f.PrevCall(AddBuff("JugDR", 10, TimeGoE, DR(35)))
		NewAction(f, DR(20)).Once(11).On(TimeGoE)
	case 6:
		f.PrevCall(AddBuff("JugDR", 10, TimeGoE, DR(40)))
		NewAction(f, DR(25)).Once(11).On(TimeGoE)
	}
	return f
}

func (f *Fight) Bastion(active int) *Fight {
	f.Add(AR(10))
	ar := 0
	switch active {
	case 2:
		ar = 18
	case 4:
		ar = 36
	case 6:
		ar = 70
	}
	f.Add(AR(ar))
	f.PrevCall(AddBuff("Bastion", 10, TimeGoE, AR(ar)))
	return f
}
